'''
游戏：
 1.选择人物
 2.购买武器(需要金币)
 3.打仗(赢了得金币)
 4.选择删除武器
 5.查看武器
 6.退出游戏
'''
import random
print('*' * 40)
print('\t\t欢迎来到王者荣耀')
print('*' * 40)
role = input('请选择游戏人物:(1.鲁班 2.后羿 3.李白 4.孙尚香 5.貂蝉 6.诸葛亮):')
coins = 1000
#定义一个自己的武器库
weapons_list = []
print('欢迎{}来到王者荣耀，当前金币是:{}'.format(role,coins))
while True:
    choice = int(input('请选择:\n 1.购买武器\n 2.打仗\n 3.删除武器\n 4.查看武器\n 5.退出游戏\n'))
    if choice == 1:
       print('欢迎来到武器库:')
       weapons = [['无尽战刃','600'],['宗师之力','650'],['饮血之刃','400'],['痛苦面具','500'],['辉月','450'],['嗜血之书','400']]
       for weapon in weapons:
           print(weapon[0],weapon[1],sep=' ')
       weaponname = input('请输入要购买的武器名称:')
       if weaponname not in weapons_list:
           for weapon in weapons:
               if weaponname == weapon[0]:
                   if coins >= int(weapon[1]):
                       coins -= int(weapon[1])
                       weapons_list.append(weapon[0]) #添加到自己的武器库
                       print('{}购买{}成功！'.format(role,weaponname))
                       break
                   else:
                       print('金币不足，赶快打仗挣金币！')
                       break
           else:
               print('输入武器名称错误！')
       else:
           print('已经拥有此武器！')

    elif choice == 2:
        print('正在进入战场....')
        if len(weapons_list) > 0:
            print('{}拥有的武器如下:'.format(role))
            for weapon in  weapons_list:
                print(weapon)
            while True:
                weaponname = input('请选择:')
                if weaponname in weapons_list:
                    ran1 = random.randint(1,20)
                    ran2 = random.randint(1,20)
                    if ran1 > ran2:
                        print('这局对战:张飞胜！！！')
                    elif ran1 < ran2:
                        coins += 200
                        print('这局游戏{}胜,剩余金币为{}！！！'.format(role,coins))
                    else:
                        print('本局平局，可以再次对战！！')
                    break
                else:
                    print('武器不存在，请重新选择！')
        else:
            print('你还没有武器，请先购买武器！')
    elif choice == 3:
        print('武器太多，很沉，丢几个....')
        if len(weapons_list) > 0:
            print('{}拥有的武器如下:'.format(role))
            for weapon in weapons_list:
                print(weapon)
            while True:
                weaponname = input('请选择要删除的武器名称:')
                if weaponname in weapons_list:
                    weapons_list.remove(weaponname)
                    for weapon in weapons:
                        if weaponname == weapon[0]:
                            coins += int(weapon[1])
                            break
                    break
                else:
                    print('武器名称输入有误！')
        else:
            print('你还没有武器，没啥可沉的....赶快购买去吧！')
    elif choice == 4:
        print('{}拥有的武器如下:'.format(role))
        for weapon in weapons_list:
            print(weapon)
        print('总金币:',coins)
    elif choice == 5:
        answer = input('确定要离开王者荣耀游戏吗(yes/no)？')
        if answer == 'yes':
            break
    else:
        print('输出错误！')
